import { configureStore } from '@reduxjs/toolkit';
import counterReducer from './modules/counter';
//NOTE- 引入业务定义的reducer
import recommendReducer from '@/views/discover/c-views/recommend/store/recommend';
import playerReducer from '@/views/player/store/player';
import {
  useSelector,
  TypedUseSelectorHook,
  useDispatch,
  shallowEqual as _shallowEqual
} from 'react-redux';
// 封装自定义useSelector

const store = configureStore({
  reducer: {
    counter: counterReducer,
    recommend: recommendReducer,
    player: playerReducer
  }
});

// 获取state的类型
type GetStateFnType = typeof store.getState;

export type IRootState = ReturnType<GetStateFnType>; // 获取函数返回值类型的类型

type DispatchType = typeof store.dispatch;

export const useAppSelector: TypedUseSelectorHook<IRootState> = useSelector; // 添加函数调用
export const useAppDispatch: () => DispatchType = useDispatch;

export const shallowEqual = _shallowEqual;

export default store;
